package com.sh.learn.ibeifeng.webservice.cxfspring;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.junit.Assert;
import org.junit.Test;

public class CxfIT {

	// TODO: 为什么调用方法报空指针
	@Test
	public void testCxf() {
		// 创建客户端的ws服务代理工厂
		ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
		// 指定要访问的webService的地址--wsdl文件的位置
		proxyFactory.setAddress("http://localhost:8080/cxf/service/test");
		// 指定要访问的方法的类型(方法的发布的接口类)
		proxyFactory.setServiceClass(TestService.class);
		// 获取指定方法
		TestService ts = (TestService) proxyFactory.create();
		// 远程的调用
		System.out.println("客户端的调用的结果是: " + ts.getvocount());
	}
	
//	@Test
//	public void testServer() throws Exception{
//		HttpClient client = new HttpClient();
//		HttpMethod method = new GetMethod("http://localhost:8080/cxf/service/test?wsdl");
//		client.executeMethod(method);
//		int status = method.getStatusLine().getStatusCode();
//        Assert.assertEquals( 200, status);
//        System.out.println(method.getResponseBodyAsString());
//        method.releaseConnection();
//	}
}
